package com.his.struts.dao.search;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import com.his.struts.dao.ry.RyImp;
import com.his.struts.form.DoctorForm;
import com.his.struts.form.UserForm;
import com.his.struts.util.DbUtil;
/**
 * 实现搜索医生的接口
 * @author liumiaoyue
 *
 */
public class SearchImp implements SearchDao {
	Logger log = Logger.getLogger(SearchImp.class);
	DbUtil db = new DbUtil();

	/**
	 * 得到医生信息
	 * 
	 * @param docName
	 *            医生名
	 * @return DoctorForm 医生
	 */
	public DoctorForm getDocInfo(String docName) {
		ArrayList list = new ArrayList();
		String sql = "select * from doctorinfo where dname =?";
		list.add(docName);
		ResultSet rs = db.executeQuery(sql, list);
		DoctorForm doc = null;
		try {
			if (rs.next()) {
				int did = rs.getInt("did");
				String docinfo = rs.getString("dinfo");
				String docemail = rs.getString("demail");
				String docpass = rs.getString("dpass");
				String docname = rs.getString("dname");
				String docposname = rs.getString("dposname");
				String docsex = rs.getString("dsex");
				String docattend = rs.getString("attend");
				String docphone = rs.getString("dphone");
				doc = new DoctorForm();
				doc.setDocphone(docphone);
				doc.setDocattend(docattend);
				doc.setDocsex(docsex);
				doc.setDocemail(docemail);
				doc.setDocpass(docpass);
				doc.setDocname(docname);
				doc.setDocposname(docposname);
				doc.setDocid(did);
				doc.setDocinfo(docinfo);
			}
		} catch (SQLException e) {
			log.error(e.getMessage());
		}finally{
			db.closeAll();
		}
		return doc;
	}
	/**
	 * 得到用户信息
	 * @param userName 用户名
	 * @return UserForm 用户form
	 */
	public UserForm getUserInfo(String userName) {
		ArrayList list = new ArrayList();
		String sql = "select * from userinfo where uname =?";
		list.add(userName);
		ResultSet rs = db.executeQuery(sql, list);
		UserForm uf = null;
		try {
			while (rs.next()) {
				int uid = rs.getInt("uid");
				String uname = rs.getString("uname");
				String uaddress = rs.getString("uaddress");
				uf = new UserForm();
				uf.setUid(uid);
				uf.setUname(uname);
				uf.setUaddress(uaddress);
			}
		} catch (SQLException e) {
			log.error(e.getMessage());
		}finally{
			db.closeAll();
		}
		return uf;
	}

}
